#ifndef _A_STAR_H_
#define _A_STAR_H_

/*
;===================================================================
;A* Pathfinder (Version 1.71a) by Patrick Lester. Used by permission.
;===================================================================
;Last updated 06/16/03 -- Visual C++ version
*/

//Declare constants
#include "typedef.h"
#include <vector>
#include <stdlib.h>
using namespace std;

class CAStar
{
public:
	CAStar():m_onClosedList(10),m_scNotStarted(0)
	{
		m_pWalkability 		= NULL;
		m_pOpenList			= NULL;
		m_pWhichList		= NULL;
		m_pOpenX			= NULL;
		m_pOpenY			= NULL;
		m_pParentX			= NULL;
		m_pParentY			= NULL;
		m_pFcost			= NULL;
		m_pGcost			= NULL;
		m_pHcost			= NULL;
		m_mapWidth = 0;
		m_mapHeight = 0;
		m_tileSize = 0;
	}
	~CAStar();
	bool Init(int mapW,int mapH,int tileSize);

	bool FindPath (int startingX, int startingY,int targetX, int targetY);
	vector<SPoint> GetPath()
	{
		return m_path;
	}
	void SetCanWalk(bool walk,uint16 x,uint16 y)
	{
		if(x >= m_mapWidth || y >= m_mapHeight)
			return;
		if(walk)
			m_pWalkability[x][y] = m_scWalkable;
		else
			m_pWalkability[x][y] = m_scUnwalkable;
	}
	bool CanWalk(uint16 x,uint16 y)
	{
		if(x >= m_mapWidth || y >= m_mapHeight)
			return false;
		return m_pWalkability[x][y] == m_scWalkable;
	}
private:

	int m_mapWidth;
	int m_mapHeight;
	int m_tileSize;
	//static const int numberPeople = 3;
	int m_onClosedList;
	int m_scNotStarted;// path-related constants
	static const char m_scWalkable = 0, m_scUnwalkable = 1;// m_pWalkability array constants

	//Create needed arrays
	char **m_pWalkability;
	uint16 *m_pOpenList;
	uint16 **m_pWhichList;
	// 		whether a cell is on the open list or on the closed list.
	uint16 *m_pOpenX;
	uint16 *m_pOpenY;
	uint16 **m_pParentX;
	uint16 **m_pParentY;
	uint16 *m_pFcost;
	uint16 **m_pGcost;
	uint16 *m_pHcost;
	vector<SPoint> m_path;
	/*uint16 m_pathLength;//[numberPeople+1];     //stores length of the found path for critter
	uint16 m_pathLocation;//[numberPeople+1];   //stores current position along the chosen path for critter		
	uint16* m_pPathBank;

	//Path reading variables
	uint16 m_pathStatus;
	uint16 m_xPath;
	uint16 m_yPath;*/
};

#endif